package ch.uzh.ifi.sonar.shells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Widget;

public abstract class Tab {

	Shell shell;
	Display display;

	Composite tabFolderPage;
	Group mainGroup;
	Group controlGroup;
	Group exampleGroup;
	Group listenersGroup;
	final SonarDashboard instance;

	Tab(SonarDashboard instance) {
		this.instance = instance;
	}

	protected void createControlGroup() {
		controlGroup = new Group(tabFolderPage, SWT.NONE);
		controlGroup.setLayout(new GridLayout(1, true));
		controlGroup
				.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		controlGroup.setText("Parameters");
	}

	abstract Widget[] getExampleWidgets();

	Composite createTabFolderPage(TabFolder tabFolder) {
		/* Cache the shell and display. */
		shell = tabFolder.getShell();
		display = shell.getDisplay();

		/* Create a two column page. */
		tabFolderPage = new Composite(tabFolder, SWT.NONE);
		tabFolderPage.setLayout(new GridLayout(1, false));
		fillContent();
		return tabFolderPage;
	}

	protected void fillContent() {
		createControlGroup();
		createMainGroup();

		/* Create the "Listeners" group under the "Control" group. */
		// createListenersGroup ();

		/* Create and initialize the example and control widgets. */
		createExampleWidgets();
		createControlWidgets();
	}

	void createExampleWidgets() {

	}

	void createControlWidgets() {

	}

	/* Create the "Listeners" group under the "Control" group. */
	void createListenersGroup() {
		listenersGroup = new Group(tabFolderPage, SWT.NONE);
		listenersGroup.setLayout(new GridLayout(3, false));
		listenersGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
				true, 2, 1));
		listenersGroup.setText("Listeners");
	};

	void createMainGroup() {
		exampleGroup = new Group(tabFolderPage, SWT.NONE);
		exampleGroup.setLayout(new GridLayout());
		exampleGroup
				.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	}

	void disposeExampleWidgets() {

	}

	void setExampleWidgetState() {

	}

	int getDefaultStyle() {
		return SWT.None;
	}

	abstract String getTabText();

}
